package com.simin.base.appdialog;

import com.simin.base.appnet.netother.RxSubscriber;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by wsm on 2024/10/21.
 * <p>
 */
public class BaseHttpDialog {

    private static CompositeSubscription compositeSubscription;

    public static <T> void addSubscription(Observable<T> observable, RxSubscriber<T> subscriber) {
        //管理所有的订阅
        compositeSubscription = new CompositeSubscription();
        compositeSubscription.add(observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(subscriber));
    }

    public static void destroyCompositeSubscription() {
        if (compositeSubscription != null
                && compositeSubscription.hasSubscriptions()) {
            //取消注册，以避免内存泄露
            compositeSubscription.unsubscribe();
        }
    }
}
